<?php
class tbdata_api_taobao extends tbdata_api_request{

    var $app_key = '10011902';
    var $app_secret = '2fc426b0109908169017efb33a71f15c';
    var $api_url = 'http://gw.api.taobao.com/router/rest';
	public function __contruct(){
		$app_info = app::get('tbdata')->getConf('taobao.appkey.setting');
		if($app_info['api_key']&&$app_info['api_secrt']&&$app_info['api_url']){
			$this->app_key = $app_info['api_key'];
			$this->app_secret = $app_info['api_secrt'];
			$this->api_url = $app_info['api_url'];
		}
	}
    public function get_std_cats($parent_cid=0){

        $params = $this->system_static_params();

        $params['method'] = 'taobao.itemcats.get';
        $params['fields'] = 'cid,parent_cid,name,is_parent';
        $params['parent_cid'] = $parent_cid;
        $params['sign'] = $this->gen_sign($params);

        return $this->request($params);
    }

    public function get_product_props($cid,$props){
        #$cid = '1512';
        #$props = '20000:26683;21041:47186826';
        $params = $this->system_static_params();

        $params['method'] = 'taobao.product.get';
        $params['fields'] = 'binds';
        $params['cid'] = $cid;
        $params['props'] = $props;
        $params['sign'] = $this->gen_sign($params);

        $re = $this->request($params);
        return $re['product_get_response']['product']['binds'];
    }
        
    #��¼URL
    public function get_login_url($url){
        $login_url = "http://container.api.taobao.com/container/identify";
        $params['app_key'] = $this->app_key;
        $params['timestamp'] = date('Y-m-d H:i:s',time());
        $params['sign_method'] = "md5";
        date_default_timezone_set('PRC');
        $params['target'] = $url;
        reset($params);
        $params['sign'] = $this->gen_sign($params);

        foreach($params as $key=>$value){
            $ps_s[] = $key."=".$value;
        }

        return $login_url.'?'.implode("&",$ps_s);
    }
    
    public function get_postages($session=''){
        $params = $this->system_static_params();
        $params['session'] = $session;
        $params['method'] = 'taobao.postages.get';
        $params['fields'] = 'postage_id,name,memo,created,modified,post_price,post_increase,express_price,express_increase,ems_price,ems_increase,postage_modes';
        $params['sign'] = $this->gen_sign($params);
        return $this->request($params);
    }
    
    public function get_shop_cats($session='',$nick=''){
        $params = $this->system_static_params();
        $params['nick'] = $nick;
        $params['method'] = 'taobao.sellercats.list.get';
        $params['sign'] = $this->gen_sign($params);
        return $this->request($params);

    }
    public function system_static_params(){
        return array('timestamp'=>date('Y-m-d H:i:s'),'format'=>'json','app_key'=>$this->app_key,'v'=>'2.0','sign_method'=>'md5',);
    }
}